using Microsoft.Phone.Controls.Primitives;
using System;
using System.Windows.Controls;
namespace Microsoft.Phone.Controls
{
	internal abstract class DataSource : ILoopingSelectorDataSource
	{
		private DateTimeWrapper _selectedItem;
		public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
		public object SelectedItem
		{
			get
			{
				return this._selectedItem;
			}
			set
			{
				if (value != this._selectedItem)
				{
					DateTimeWrapper dateTimeWrapper = (DateTimeWrapper)value;
					if (dateTimeWrapper == null || this._selectedItem == null || dateTimeWrapper.DateTime != this._selectedItem.DateTime)
					{
						object selectedItem = this._selectedItem;
						this._selectedItem = dateTimeWrapper;
						EventHandler<SelectionChangedEventArgs> selectionChanged = this.SelectionChanged;
						if (selectionChanged != null)
						{
							selectionChanged.Invoke(this, new SelectionChangedEventArgs(new object[]
							{
								selectedItem
							}, new object[]
							{
								this._selectedItem
							}));
						}
					}
				}
			}
		}
		public object GetNext(object relativeTo)
		{
			DateTime? relativeTo2 = this.GetRelativeTo(((DateTimeWrapper)relativeTo).DateTime, 1);
			if (!relativeTo2.get_HasValue())
			{
				return null;
			}
			return new DateTimeWrapper(relativeTo2.get_Value());
		}
		public object GetPrevious(object relativeTo)
		{
			DateTime? relativeTo2 = this.GetRelativeTo(((DateTimeWrapper)relativeTo).DateTime, -1);
			if (!relativeTo2.get_HasValue())
			{
				return null;
			}
			return new DateTimeWrapper(relativeTo2.get_Value());
		}
		protected abstract DateTime? GetRelativeTo(DateTime relativeDate, int delta);
	}
}
